
import _pygamesvg, pygame
from pygame.locals import SRCALPHA

def renderSVGFile(surface, fileObj, position=(0, 0), size=(0, 0), scale=(1.0, 1.0), alpha=1.0):
    """ Render an SVG image given a file object. """
    renderSVG(surface, fileObj.read(), position, size, scale, alpha)

def renderSVG(surface, svgData, position=(0, 0), size=(0, 0), scale=(1.0, 1.0), alpha=1.0): 
    """ Render an SVG image given a string containing the SVG data. """
    assert isinstance(surface, pygame.Surface)
    if scale[0] <= 0:
        scale = 1.0, scale[1]
    if scale[1] <= 0:
        scale = scale[0], 1.0
    _pygamesvg.render(surface, svgData, position, size, scale, alpha)

def fileToSurface(fileObject, size=(0, 0), scale=(1.0, 1.0), alpha=1.0):
    """ Read an SVG file from a file object and return a pygame surface containing the SVG graphic. """
    return toSurface(fileObject.read(), size, scale, alpha)

def toSurface(svgData, size=(0, 0), scale=(1.0, 1.0), alpha=1.0):
    """ svgData - string containing the SVG info
    size - Size to render the SVG at. 0, 0 means the original size will be used.
    backgroundColor - background color to render the SVG to. 
    flags - flags to be passed to pygame.Surface """
    #print surface.get_alpha()
    return _pygamesvg.toSurface(svgData, size, scale, alpha)

def size(svgData):
    """ Get the (width, height) of an SVG document """
    return _pygamesvg.size(svgData)
